package com.server.util;

import com.server.meta.ClassMeta;

import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 * Busline: sunguangzhu
 * Date: 13-8-10
 * Time: 下午8:57
 * To change this template use File | Settings | File Templates.
 */
public class JsUIUtils {
    public static String getColumnUI(Field field, String comment, ClassMeta classMeta) {
//        String cloumnUI = "<th data-options=\"field:'" + field.getName() + "', width:100, align:'center'\">" + comment + "</th>";
        String cloumnUI = "{field:'" + field.getName() + "', title:'" + comment + "', width:100,align:'center'}";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
        } else if (fieldTypeName.contains("Integer")) {
        } else if (fieldTypeName.contains("Long")) {
        } else if (fieldTypeName.contains("Boolean")) {
        } else if (fieldTypeName.contains("Float")) {
        } else if (fieldTypeName.contains("Double")) {
        } else if (fieldTypeName.contains("Date")) {
        } else if (fieldTypeName.contains("Set")) {
        } else {
            cloumnUI = "{field:'" + field.getName() + ".name', title:'" + comment + "', width:100,align:'center'}";
//            cloumnUI = "<th data-options=\"field:'" + field.getName() + ".name', width:100, align:'center'\">" + comment + "</th>";
        }
        return cloumnUI;
    }

    public static String getColumnConditionUI(Field field, String comment, ClassMeta classMeta) {
        String cloumnUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            cloumnUI = field.getName() + ": {required: true}";
        } else if (fieldTypeName.contains("Integer")) {
            cloumnUI = field.getName() + ": {element: 'numberbox'}";
        } else if (fieldTypeName.contains("Long")) {
            cloumnUI = field.getName() + ": {element: 'numberbox'}";
        } else if (fieldTypeName.contains("Boolean")) {
            cloumnUI = field.getName() + ":{element: 'numberbox'}";
        } else if (fieldTypeName.contains("Float")) {
            cloumnUI = field.getName() + ": {element: 'numberbox'}";
        } else if (fieldTypeName.contains("Double")) {
            cloumnUI = field.getName() + ": {element: 'numberbox'}";
        } else if (fieldTypeName.contains("Date")) {
            cloumnUI = field.getName() + ":{element: 'datetimebox', formatter: Utils.formaterDateTime}";
        } else if (fieldTypeName.contains("Set")) {
            cloumnUI = "";
        } else {//复合对象（下拉框）
            cloumnUI = field.getName() + ":{element: 'combobox', url: Constants.ctx+'" + field.getName() + "/getKeyValueDtos.do', valueField: 'id', textField: 'name', panelHeight: 'auto'}";
        }
        return cloumnUI;
    }

    public static String getComplexObject(Field field) {
        String complexObject = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
        } else if (fieldTypeName.contains("Integer")) {
        } else if (fieldTypeName.contains("Long")) {
        } else if (fieldTypeName.contains("Boolean")) {
        } else if (fieldTypeName.contains("Float")) {
        } else if (fieldTypeName.contains("Double")) {
        } else if (fieldTypeName.contains("Date")) {
        } else if (fieldTypeName.contains("Set")) {
        } else {//复合对象（下拉框）
            complexObject = field.getName();
        }
        return complexObject;
    }

    public static String getInputUI(Field field, String comment, ClassMeta classMeta) {
        String inputUI = "";
        String commonUI = "<tr><td>" + comment + "</td><td><input type=\"text\" name=\"" + field.getName() + "\"></td></tr>";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Integer")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Long")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Boolean")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Float")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Double")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Date")) {
            inputUI = commonUI;
        } else if (fieldTypeName.contains("Set")) {
            inputUI = "";
        } else {
            inputUI = "<tr><td>" + comment + "</td><td><input id=\"" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + ".id\"></td></tr>";
        }
        return inputUI;
    }

    public static String getViewUI(Field field, String comment, ClassMeta classMeta) {
        String viewUI = "";
        String fieldTypeName = field.getGenericType().toString();
        if (fieldTypeName.contains("String")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Integer")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Long")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Boolean")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Float")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Double")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Date")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else if (fieldTypeName.contains("Set")) {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        } else {
            viewUI = "<tr><td>" + comment + "</td><td><input id=\"${moduleName}" + field.getName() + "\" type=\"text\" name=\"" + field.getName() + "\" value=\"${bean." + field.getName() + "}\"></td></tr>";
        }
        return viewUI;
    }

   /* public static String getMenuUI(ClassMeta classMeta,String comment) {
        String menuUI = "<div><a href=\"#\" onclick=\"addTab('"+comment+"','"+classMeta.getLowerClassName()+"/index.do')\">"+comment+"</a></div>";
        return menuUI;
    }*/
}
